package com.customization.xinri;

import com.engine.core.cfg.annotation.CommandDynamicProxy;
import com.engine.core.interceptor.AbstractCommandProxy;
import com.engine.core.interceptor.Command;
import com.engine.workflow.cmd.requestForm.RequestSubmitCmd;
import com.engine.workflow.entity.requestForm.RequestOperationResultBean;
import weaver.hrm.User;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;



/**
 * @Classname CustomRequestSubmitCmd
 * @Description TODO()
 * @Author wanxq
 * @Date 2019-08-21 14:49
 **/


@CommandDynamicProxy(target = RequestSubmitCmd.class, desc = "流程提交后给调用接口")
public class CustomRequestSubmitCmd extends AbstractCommandProxy<Map<String, Object>> {


    @Override
    public Map<String, Object> execute(Command<Map<String, Object>> targetCommand) {
        //获取到被代理对象
        RequestSubmitCmd requestSubmitCmd = (RequestSubmitCmd) targetCommand;
        //获取被代理对象的参数
        Map<String, Object> params = requestSubmitCmd.getParams();
        //对参数做预处理
        requestSubmitCmd.writeLog("requestSubmitCmd params222======" + params);

        String remark = ((String) params.get("remark")).trim();
        requestSubmitCmd.writeLog("requestSubmitCmd remark222======" + remark);
        //参数回写
        requestSubmitCmd.setParams(params);
        //执行标准的业务处理
        Map<String, Object> result = nextExecute(targetCommand);
        //对返回值做加工处理

        RequestOperationResultBean resultBean = (RequestOperationResultBean) result.get("data");
        String executeResult = resultBean.getType().name();
        requestSubmitCmd.writeLog("requestSubmitCmd executeResult======" + executeResult);
        if ("SUCCESS".equals(executeResult)) {
            HttpServletRequest request = requestSubmitCmd.getRequest();
            User user = requestSubmitCmd.getUser();
            String workflowid = (String) params.get("workflowid");
            String nodeid = (String) params.get("nodeid");
            requestSubmitCmd.writeLog("requestSubmitCmd workflowid======" + workflowid);
            requestSubmitCmd.writeLog("requestSubmitCmd nodeid======" + nodeid);
            requestSubmitCmd.writeLog("requestSubmitCmd user======" + user.getUID());
            //if (("1025".equals(workflowid) || "1029".equals(workflowid))) {
            //if (!"1164".equals(nodeid) && !"1166".equals(nodeid)) {
            String requestid = (String) params.get("requestid");
            requestSubmitCmd.writeLog("requestSubmitCmd requestid======" + requestid);
//            RequestService requestService = new RequestService();
//            RequestInfo requestInfo = requestService.getRequest(Integer.parseInt(requestid));
//            String tablename = requestInfo.getRequestManager().getBillTableName();
//            requestSubmitCmd.writeLog("requestSubmitCmd tablename======" + tablename);

            // }
            // }
        }

        return result;
    }


}
